<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
  var str = 'username=haha&userpwd=123123';
  str = str.split('&');
  var obj = {};
  for(var i = 0; i<str.length; i++){
    // console.log(str[i].replace('=',':'));
    var s = str[i].replace('=',':');
    var b = s.split(":");
    // console.log(b);
   
    for(var j =0;j<b.length;j++){
      obj[b[0]]=b[1]
      // console.log(obj)
    }
  } 
  console.log(obj);
  // for(var k in obj){
  //   console.log(k);
  //   console.log(obj[k]);
  // }
  </script>
  
</body>
</html>